home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_Install3.adf / piarc.LZH / PALRD.rexx < prev    next >
OS/2 REXX Batch file  |  1992-04-09  |  5KB  |  186 lines

  1. /*
  2.  * PALRD.rexx
  3.  *
  4.  *  Written by: Pete Patterson
  5.  * Last Update: April 14, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.00
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate rgbxr.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41.   /*
  42.    * This code attempts to read a file called "picmdpath" from REXX:
  43.    * If it can't find it, the script will assume that the commands
  44.    * associated with this PI Module are in "c:". If the file exists,
  45.    * the script will look in the path that is specified in the file.
  46.    * If you create this file, you MUST put a complete, correct path
  47.    * in it; if the commands are in a sub-directory, you have to put
  48.    * the trailing slash on the path (like, device:dir/).
  49.    * 
  50.    */
  51.   cmdpath = 'c:';
  52.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  53.     do
  54.       cmdpath = readln(fhandle);
  55.       call close(fhandle);  /* close the file    */
  56.     end
  57.  
  58. options;
  59. address;
  60.  
  61.   prevpath = 'ram:'; /* put user in ram to start with... */
  62.  
  63.   if show('C',palpath) = 1 then do
  64.     prevpath = getclip(palpath);
  65.     end;
  66.  
  67.   address(prtnme);
  68.   options results;
  69.   'filerequest "'||prevpath||'","'||bufname||'","","Get IFF Palette"';
  70.   palfile = result;
  71.   options;
  72.  
  73.   if palfile = 'FR_CANCELLED' then do
  74.     address(prtnme);
  75.     'imtofront';
  76.     exit 0;
  77.     end;
  78.  
  79.   palfile = expandfilename(palfile);
  80.   thispath = gimmepath(palfile);
  81.   call setclip(palpath,thispath);
  82.  
  83.   address(prtnme);
  84.   options results;
  85.   'askyn '||'"Verbatim Palette" "Stretch Palette"'
  86.   stretch = result;
  87.   options;
  88.  
  89.   if stretch then do
  90.     address command cmdpath||'PALRD "'||palfile||'" -s';
  91.     end;
  92.   else do
  93.     address command cmdpath||'PALRD "'||palfile||'"';
  94.     end;
  95.   if rc ~= 0 then do
  96.     address(prtnme);
  97.     'message "Cannot read '||palfile||'"';
  98.     exit 0; /* this is not a proper IFF file */
  99.     end;
  100.  
  101.   res = open(fhandle,'ram:IP_PALRD.tmp','read');      /* open the file */
  102.   if res then do
  103.     rstring = readln(fhandle);
  104.     parse var rstring colors
  105.     address(prtnme);
  106.     if colors < 256 then do
  107.       options results;
  108.       'askprop '||'"Start offset in palette?" 0 0 '||256-colors
  109.       paloffs = result;
  110.       options;
  111.       end;
  112.     else do
  113.       paloffs = 0;
  114.       end;
  115.     do ccolr = 1 to colors
  116.       rstring = readln(fhandle);
  117.       parse var rstring rv '/' gv '/' bv
  118.        address(prtnme);
  119.       'setpalette '||paloffs+ccolr-1||' '||rv||' '||gv||' '||bv
  120.       end;
  121.     call close(fhandle);
  122.     end;
  123.   address command 'c:delete >nil: ram:IP_PALRD.tmp';
  124.   
  125.   address(prtnme);
  126.   'imtofront'; /* show user the IM screen */
  127.   /* is there already a primary buffer??? */
  128.   options results;
  129.   'current';
  130.   bufdata = result;
  131.   options;
  132.  
  133.   exit 0;
  134.  
  135. /*
  136.  * gimmepath
  137.  *
  138.  * This takes the provided argument and sucks the path out of it, then
  139.  * returns that path to the caller, sans file name.
  140.  */
  141. gimmepath:
  142.   arg fullnamegx;
  143.     tempgx = reverse(fullnamegx);
  144.     lengx = length(fullnamegx);   /* get length of string */
  145.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  146.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  147.     seploc = 0; /* assumes current dir, no path supplied */
  148.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  149.       seploc = (lengx - slashdex)+1;
  150.       end;
  151.     else do
  152.       if colondex ~= 0 then do /* we assume we are on a device */
  153.         seploc = (lengx - colondex)+1;
  154.         end;
  155.       end;
  156.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  157.   gxpath = left(fullnamegx,seploc);
  158.   return(gxpath);
  159.  
  160. /*
  161.  * Since this script can't be expected to know where the CD of the user
  162.  * is when this cmd is invoked, we have to check the path the user
  163.  * provides - if it's not specified right from a root, then we have
  164.  * to make it a complete specification from the root.
  165.  */
  166. expandfilename:
  167.   parse arg jfile;
  168.   if index(jfile,':') = 0 then do
  169.     curdir = pragma(D);
  170.     if right(curdir,1) ~= ':' then do
  171.       if right(curdir,1) ~= '/' then do
  172.         if curdir ~= '' then do
  173.           curdir = curdir || '/';
  174.           end;
  175.         end;
  176.       end;
  177.     jfile = curdir||jfile;
  178.     end;
  179.   return(jfile);
  180.  
  181. rvalue:
  182.   wordnum = c2d(readch(fhandle,1)) * 256;
  183.   wordnum = wordnum + c2d(readch(fhandle,1));
  184.   return wordnum;
  185.  
  186.